package com.qianxing.utils;

import org.apache.commons.fileupload.disk.DiskFileItem;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import java.io.File;

public class MultipartFileToFileUtils {
    /**
     * 利用apache工具将MultipartFile转换为File
     *
     * @param multiFile 参数
     * @return 执行结果
     */
    public static File multipartFileToFile(MultipartFile multiFile) {
        //利用阿帕奇commons-fileupload实现类型转换
        CommonsMultipartFile commonsmultipartfile = (CommonsMultipartFile) multiFile;
        DiskFileItem diskFileItem = (DiskFileItem) commonsmultipartfile.getFileItem();
        File file = diskFileItem.getStoreLocation();
        return file;
    }

}
